//
// Created by jiao on 2021/4/19.
//

#ifndef NATIVEHANDLERDEMO_YHMAINHANDLER_H
#define NATIVEHANDLERDEMO_YHMAINHANDLER_H

#include <sys/types.h>
#include "YHHandler.h"
#include "vector"
#include "android/looper.h"

class YHMainHandler : public YHHandler {
public:
    YHMainHandler(YqHandlerCallBackFunc *callBack);

    ~YHMainHandler();

    void sendMessage(int ident, void *data);

    void removeMessage(int ident);

    void removeAll();

    void quit();

private:
    static int mainLooperCallBack(int fd, int events, void *data);

    void runMain();

    void destroy();


    void wake();

    void awoken();

    volatile bool isQuit = false;
    pthread_mutex_t mLooper_mutex_{};
    YqHandlerCallBackFunc *mCallBack;
    std::vector<std::pair<int, void *>> mQueue;
    int mEventFd;
    ALooper *mainLopper;
};


#endif //NATIVEHANDLERDEMO_YHMAINHANDLER_H
